package org.dark.fund.utils;

import cn.hutool.core.util.StrUtil;
import org.jasypt.util.text.BasicTextEncryptor;

public class EncryptUtil {

    private final static String salt = "wanglh_sort";
    private final static BasicTextEncryptor textEncryptor = new BasicTextEncryptor();

    static {
        textEncryptor.setPassword(salt);
    }

    /**
     * 明文加密
     * @param plaintext
     * @return
     */
    public static String encrypt(String plaintext) {
        return textEncryptor.encrypt(plaintext);
    }

    /**
     * 秘文解密
     * @param ciphertext
     * @return
     */
    public static String decrypt(String ciphertext) {
        return textEncryptor.decrypt(ciphertext);
    }

    /**
     * 是否匹配
     * @param plaintext
     * @param ciphertext
     * @return
     */
    public static boolean check(String plaintext, String ciphertext) {
        return StrUtil.equals(plaintext, textEncryptor.decrypt(ciphertext));
    }

}
